package com.secondhand.project.mapper;

import com.secondhand.project.domain.ChatInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ChatInfoMapper {
    ChatInfo selectChatInfoById(Long id);

    List<ChatInfo> selectChatInfoList(ChatInfo chatInfo);

    int insertChatInfo(ChatInfo chatInfo);

    int updateChatInfo(ChatInfo chatInfo);

    int deleteChatInfoById(Long id);

    int deleteChatInfoByIds(Long[] ids);


    @Select("select count(*) from chat_info where user_id = #{chatUserId} and chat_user_id = #{userId} and isread = '否'")
    Long selectUnReadChatNum(@Param("userId") Long userId, @Param("chatUserId") Long chatUserId);

    List<ChatInfo> selectUserChat(@Param("userId") Long userId, @Param("chatUserId") Long chatUserId);

    @Update("update chat_info set isread = '是' where user_id = #{chatUserId} and chat_user_id = #{userId}")
    void updateRead(@Param("userId") Long userId, @Param("chatUserId") Long chatUserId);
}
